function tweakBlog(divId) {
  Element.toggle('collapsed_blog_' + divId);
  Element.toggle('full_blog_' + divId);
}

var allSpinners = {};

function Spinner(options, inputId, inputName, initialValue, onChange) {
  this.options = options;
  this.id = inputId;
  this.spanId = 'spinner_' + inputId;
  this.name = inputName;
  this.currentIdx = 0;
  for(var i = 0; i < options.length; i++) {
    if (options[i].key == initialValue) {
      this.currentIdx = i;
    }
  }
  document.write("<span id='" + this.spanId + "'></span>");
  allSpinners[this.id] = this;
  this.onChange = onChange;
}

Spinner.prototype.show = function() {
  with(this) {
    $(spanId).innerHTML = '';
    new Insertion.Bottom(spanId, '<input type="hidden" id="' + id + '" name="' + name + '" value="' + options[currentIdx].key + '"/>');
    new Insertion.Bottom(spanId, '<div style="width:15%; float:left;"><a class="link-size" href="javascript:allSpinners[\'' + id + '\'].left()">&lt;&lt; </a></div>');
    new Insertion.Bottom(spanId, '<div style="width:70%; float:left; text-align:center;">' + options[currentIdx].display + '</div>');
    new Insertion.Bottom(spanId, '<div style="width:15%; float:right; text-decoration:none;"><a class="link-size" href="javascript:allSpinners[\'' + id + '\'].right()"> &gt;&gt;</a></div>');
  }
}

Spinner.prototype.left = function() {
  with(this) {
    currentIdx--;
    if (currentIdx < 0) {
      currentIdx = options.length - 1;
    }
    show();
    eval(onChange);
  }
}

Spinner.prototype.right = function() {
  with(this) {
    currentIdx++;
    currentIdx %= options.length;
    show();
    eval(onChange);
  }
}
var currentDivId;
function loadStoryFragment(base, storyId, divIndex) {
  var divId = 'popup_' + storyId +'_' + divIndex;
  currentDivId = divId;
  var url = base + '/Display.action?id=' + storyId + '&destJsp=' + '/display/storyFragment.jsp';
  setTimeout("renderDiv('" + url + "', '" + divId + "')", 500);
}

function renderDiv(url, divId) {
  if (divId == currentDivId) {
    new Ajax.Updater(divId, url,
      {onSuccess: function() {$(divId).show()}});
  }
}

function $E(elementType, innerText) {
  var el = $(document.createElement(elementType));
  if(innerText) { el.innerHTML = innerText; }
  return el;
}

function clearElements(nodeId) {
  var node = $(nodeId);
  var len = node.childNodes.length;

  while (node.hasChildNodes()) {
    node.removeChild(node.firstChild);
  }
}

var WindowSize = {
  width: function() {
    return window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth);
  },

  height: function() {
    return window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight);
  }
}